package edu.gatech.cs2340.bytebankers.view;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;

import edu.gatech.cs2340.bytebankers.presenter.ITownPresenter;
import java.awt.Font;
import java.awt.Color;

public class TownView extends JPanel implements ITownView {
    private String townName;
    private ITownPresenter presenter;
    private JLabel townimage, lblStoreName;
    private JButton btnStore, btnContinue, btnMenu;
    private ActionListener buttonListener;

    public TownView(ITownPresenter presenter) {
	this.presenter = presenter;

	setLayout(null);

	buttonListener = new ButtonListener();

	btnContinue = new JButton("Continue");
	btnContinue.setBounds(123, 436, 117, 29);
	btnContinue.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent arg0) {
	    }
	});
	add(btnContinue);
	btnContinue.addActionListener(buttonListener);

	btnMenu = new JButton("Menu");
	btnMenu.setBounds(6, 436, 117, 29);
	btnMenu.addActionListener(buttonListener);
	add(btnMenu);

	JLabel lblCongratulationsYouHave = new JLabel(
		"Congratulations you have reached:");
	lblCongratulationsYouHave.setForeground(Color.WHITE);
	lblCongratulationsYouHave.setFont(new Font("Lucida Grande", Font.PLAIN,
		15));
	lblCongratulationsYouHave.setBounds(297, 70, 254, 20);
	add(lblCongratulationsYouHave);

	lblStoreName = new JLabel(townName);
	lblStoreName.setForeground(Color.WHITE);
	lblStoreName.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
	lblStoreName.setBounds(297, 90, 254, 20);
	add(lblStoreName);

	/*
	 * JButton btnMenu = new JButton("Menu"); btnMenu.setBounds(375, 460,
	 * 83, 20); add(btnMenu); add(btnContinue);/*
	 * 
	 * /** Add the background image for the town.
	 */
    }

    @Override
    public void setTownName(String name) {
	this.townName = name;
	lblStoreName.setText(townName);
    }

    @Override
    public void setHasStore(boolean hasStore) {
	if (hasStore == true) {
	    btnStore = new JButton("Store");
	    btnStore.setBounds(238, 436, 117, 29);
	    btnStore.addActionListener(buttonListener);
	    add(btnStore);
	}
	townimage = new JLabel("");
	townimage
		.setIcon(new ImageIcon(
			StoreBGView.class
				.getResource("/edu/gatech/cs2340/bytebankers/graphics/TownBGImg.png")));
	townimage.setBounds(0, 0, 860, 500);
	add(townimage);

    }

    /**
     * Private Inner class for Button Listeners
     */
    private class ButtonListener implements ActionListener {
	public void actionPerformed(ActionEvent event) {
	    if (event.getSource() == btnContinue) {
		onContinueClick();
	    }
	    if (event.getSource() == btnStore) {
		onStoreClick();
	    } else if (event.getSource() == btnMenu) {
		onMenuClick();
	    }
	}
    }

    public void onContinueClick() {
	presenter.OnContinueClick();
    }

    public void onStoreClick() {
	presenter.onStoreclick();

    }

    public void onMenuClick() {
	presenter.onMenuClick();

    }

    public JPanel getMainPanel() {
	return this;
    }
}
